<?php
/*
 * Author :pandiam
 */
require_once ('include/css_head.php');
require_once ('include/functions.php');
require_once ('include/header.php');

require_once ('../BL/BL.php');
require_once ('include/functions.php');
require_once ('../Frameworks/Objects/entity.php');
require_once ('../Frameworks/Objects/attribute.php');
require_once ('../Frameworks/Objects/category.php');

if (!isset($_SESSION['uid']) || $_SESSION['uid'] == -1) {
    UI_registerError('msg_warning', "You are not logged in.");
    header('Location: login.php');
    exit(0);
}

if ( isset($_GET['id']) )
{
    if ( !ctype_digit((string)$_GET['id']) ) {
        UI_registerError('msg_error', "Invalid category request");
        header("location: index.php");
        exit(0);
    }
    $catid = $_GET['id'];
}
else
{
    UI_registerError('msg_warning', "You haven't selected a category to delete entities from!");
    header("location: profile.php");
    exit(0);
}

$cat = BL_getCategory($catid);
$entities = BL_selectCategory($catid);

$entityNames="";
$i=0;
foreach($entities as $ent){
    if($i==0)
        $entityNames = $ent->getName();
    else
        $entityNames = $entityNames.",".$ent->getName();
$i++;
}
?>

<script type="text/javascript" src="js/deleteEntity.js"></script>

<div id="sideBar" style="float:left">
</div>

<div id="profileContent" style="margin-left: 10px;">
</div>


<script type="text/javascript">
        $.ajaxSetup ({ cache: false });
        var ajax_load = "<img src='images/load.gif' alt='loading...' />";
        $("#sideBar").load($("#sideBar").html(ajax_load).load('profileSideBar.php'));
</script>

<form id="deleteEntityForm" name="deleteEntityForm" action="deleteEntityDo.php" method="post">
<div style="margin-left: 30%;">
    <span>Using the <img src="images/delete_button.png" alt="delete" /> button you can delete an existing entity in this category</span>
</div>
<div style="margin-left:35%">

    <h1>Entities List</h1>
    <div id="visMatrix">
    </div>
    <input type="hidden" name="catId" value="<? echo $catid ?>"/>
    <input type="hidden" name="data" />
    <input type="button" onclick="javascript:passData()" value="Submit" />
</div>
</form>


<script type="text/javascript">
        $.ajaxSetup ({ cache: false });
        var ajax_load = "<img src='images/load.gif' alt='loading...' />";
        $("#sideBar").load($("#sideBar").html(ajax_load).load('profileSideBar.php'));
        convert(<?php echo "\"".$entityNames."\"" ?>);
        changeContent();
</script>